/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.util;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author toint
 */
public class DBConfig {
    private static String user = "";
    private static String passworld = "";
    private static String url = "";
    public static Connection getConnection(){
        try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                url = "jdbc:sqlserver://localhost:1433;databasename=vietnam;useUnicode=true&amp;characterEncoding=UTF-8";//citicom public
                user = "sa";//
                passworld = "12345";//

            return DriverManager.getConnection(url, user, passworld);
        } catch (SQLException ex) {
            Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    /**
     *
     */
    public static void destroy(Connection connection, CallableStatement stm, ResultSet rs) throws SQLException{
        if((rs != null) && !(rs.isClosed())){
            rs.close();
        }
        if((stm != null) && !(stm.isClosed())){
            stm.close();
        }
        if(connection != null && !(connection.isClosed())){
            connection.close();
        }

    }

}
